Micron Document
🎖️GitЯра🎖️

Node / meshtastic / Meshtastic-Android / files / feature / settings / src / commonTest / kotlin / org / meshtastic / feature / settings / channel / CommonChannelViewModelTest.kt

Displaying Raw • Download

feature/settings/src/commonTest/kotlin/org/meshtastic/feature/settings/channel/CommonChannelViewModelTest.kt 65a1f5ce4d0e4b8eafcd0bbfccafd41dc6ee888a (65a1f5ce) Text, 3.85 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.feature.settings.channel

Tff7b72import T7ee787app.cash.turbine.test
Tff7b72import T7ee787dev.mokkery.MockMode
Tff7b72import T7ee787dev.mokkery.answering.returns
Tff7b72import T7ee787dev.mokkery.every
Tff7b72import T7ee787dev.mokkery.matcher.any
Tff7b72import T7ee787dev.mokkery.mock
Tff7b72import T7ee787dev.mokkery.verify
Tff7b72import T7ee787io.kotest.matchers.shouldBe
Tff7b72import T7ee787kotlinx.coroutines.Dispatchers
Tff7b72import T7ee787kotlinx.coroutines.ExperimentalCoroutinesApi
Tff7b72import T7ee787kotlinx.coroutines.flow.MutableStateFlow
Tff7b72import T7ee787kotlinx.coroutines.test.UnconfinedTestDispatcher
Tff7b72import T7ee787kotlinx.coroutines.test.resetMain
Tff7b72import T7ee787kotlinx.coroutines.test.runCurrent
Tff7b72import T7ee787kotlinx.coroutines.test.runTest
Tff7b72import T7ee787kotlinx.coroutines.test.setMain
Tff7b72import T7ee787org.meshtastic.core.repository.PlatformAnalytics
Tff7b72import T7ee787org.meshtastic.core.repository.RadioConfigRepository
Tff7b72import T7ee787org.meshtastic.core.testing.FakeRadioController
Tff7b72import T7ee787org.meshtastic.proto.ChannelSet
Tff7b72import T7ee787org.meshtastic.proto.Config
Tff7b72import T7ee787org.meshtastic.proto.LocalConfig
Tff7b72import T7ee787kotlin.test.AfterTest
Tff7b72import T7ee787kotlin.test.BeforeTest
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals

Tf0883e@OptInTb4b4b4(Te6edf3ExperimentalCoroutinesApiTff7b72::Te6edf3classTb4b4b4)
Tff7b72abstract Tff7b72class T56d364CommonChannelViewModelTest Tb4b4b4{

Tff7b72protected Tff7b72val Te6edf3radioController Tff7b72= Te6edf3FakeRadioControllerTb4b4b4(Tb4b4b4)
Tff7b72protected Tff7b72val Te6edf3radioConfigRepositoryTb4b4b4: Te6edf3RadioConfigRepository Tff7b72= Te6edf3mockTb4b4b4(Te6edf3MockModeTb4b4b4.Te6edf3autofillTb4b4b4)
Tff7b72protected Tff7b72val Te6edf3analyticsTb4b4b4: Te6edf3PlatformAnalytics Tff7b72= Te6edf3mockTb4b4b4(Te6edf3MockModeTb4b4b4.Te6edf3autofillTb4b4b4)
Tff7b72protected Tff7b72val Te6edf3testDispatcher Tff7b72= Te6edf3UnconfinedTestDispatcherTb4b4b4(Tb4b4b4)

Tff7b72protected Tff7b72lateinit Tff7b72var Te6edf3viewModelTb4b4b4: Te6edf3ChannelViewModel

Tf0883e@BeforeTest
Tff7b72fun Td2a8ffsetupRepoTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3DispatchersTb4b4b4.Te6edf3setMainTb4b4b4(Te6edf3testDispatcherTb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3localConfigFlow Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Te6edf3LocalConfigTb4b4b4(Tb4b4b4)Tb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3channelSetFlow Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Te6edf3ChannelSetTb4b4b4(Tb4b4b4)Tb4b4b4)

Te6edf3viewModel Tff7b72= Te6edf3ChannelViewModelTb4b4b4(Te6edf3radioControllerTb4b4b4, Te6edf3radioConfigRepositoryTb4b4b4, Te6edf3analyticsTb4b4b4)
Tb4b4b4}

Tf0883e@AfterTest
Tff7b72fun Td2a8fftearDownTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3DispatchersTb4b4b4.Te6edf3resetMainTb4b4b4(Tb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`isManaged returns true when security is managed`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Tff7b72val Te6edf3config Tff7b72= Te6edf3LocalConfigTb4b4b4(Te6edf3security Tff7b72= Te6edf3ConfigTb4b4b4.Te6edf3SecurityConfigTb4b4b4(Te6edf3is_managed Tff7b72= Tff7b72trueTb4b4b4)Tb4b4b4)
Te6edf3every Tb4b4b4{ Te6edf3radioConfigRepositoryTb4b4b4.Te6edf3localConfigFlow Tb4b4b4} Te6edf3returns Te6edf3MutableStateFlowTb4b4b4(Te6edf3configTb4b4b4)
Te6edf3viewModel Tff7b72= Te6edf3ChannelViewModelTb4b4b4(Te6edf3radioControllerTb4b4b4, Te6edf3radioConfigRepositoryTb4b4b4, Te6edf3analyticsTb4b4b4)

Te6edf3viewModelTb4b4b4.Te6edf3localConfigTb4b4b4.Te6edf3test Tb4b4b4{
Te6edf3awaitItemTb4b4b4(Tb4b4b4)Tb4b4b4.Te6edf3securityTff7b72?.Te6edf3is_managed Te6edf3shouldBe Tff7b72true
Te6edf3assertEqualsTb4b4b4(Tff7b72trueTb4b4b4, Te6edf3viewModelTb4b4b4.Te6edf3isManagedTb4b4b4)
Te6edf3cancelAndIgnoreRemainingEventsTb4b4b4(Tb4b4b4)
Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`txEnabled updates config via radioController`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Te6edf3viewModelTb4b4b4.Te6edf3txEnabled Tff7b72= Tff7b72true
T8b949e// FakeRadioController doesn't track setLocalConfig calls yet, but it's fine for coverage
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`trackShare calls analytics`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3viewModelTb4b4b4.Te6edf3trackShareTb4b4b4(Tb4b4b4)
Te6edf3verify Tb4b4b4{ Te6edf3analyticsTb4b4b4.Te6edf3trackTb4b4b4(Ta5d6ff"Ta5d6ffshareTa5d6ff"Tb4b4b4, Te6edf3anyTb4b4b4(Tb4b4b4)Tb4b4b4) Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`requestChannelUrl sets requestChannelSet`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
T8b949e// Use a guaranteed valid Meshtastic URL
Tff7b72val Te6edf3url Tff7b72= Ta5d6ff"Ta5d6ffhttps://www.meshtastic.org/e/#CgMSAQESBggBQANIAQTa5d6ff"
Te6edf3viewModelTb4b4b4.Te6edf3requestChannelUrlTb4b4b4(Te6edf3urlTb4b4b4) Tb4b4b4{Tb4b4b4}
Te6edf3runCurrentTb4b4b4(Tb4b4b4)

Te6edf3assertEqualsTb4b4b4(Tff7b72trueTb4b4b4, Te6edf3viewModelTb4b4b4.Te6edf3requestChannelSetTb4b4b4.Te6edf3value Tff7b72!Tff7b72= Tff7b72nullTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s